 <%--
 *  File:   MonthBuyData.jsp
 *  Desc:	the Lend slip summary page
 *
 *  Date		  Author		   Changes
 *  2011-6-20	  JackYin		  Created
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%
  //init param
  String privilegeCode = "A0110";
  String strTableName = "v_zylmonthbuydatasummary";
  String strModuleName = "COM";
  String contextPath = request.getContextPath();
%>
<%@ include file="/inc/CommonHeader.inc" %>
<%@ include file="/inc/OvalLocationDefault.inc" %>
<%@ include file="/inc/Security.inc" %>
<html>
<head>
<title>HospitalBuySaleStock.jsp</title>
<PageFlow:CheckPageFlow pageName="p_monthbuydatasummary"/>
<%@ include file="/inc/CatchError.inc" %>
<%@ include file="/inc/SumDiv.inc" %>
<%@ include file="/rpt/ReportURL.inc" %>
<%
HashMap userinfo = (HashMap)session.getAttribute("userinfo");
String  issalesman = (String) userinfo.get("issalesman");
String  username = (String) userinfo.get("employeename");

java.util.Calendar cal = java.util.Calendar.getInstance();   
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/SummaryDivision.js"></script>
<script language="JavaScript">
function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  editform.action = "MonthBuyData.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}

function clickRow(obj,idx)
{
  var cform = document.cform;
  cform.radiorow[idx].checked=true;
  cform.historyofmonthpurchaseid.value = eval('obj.all.historyofmonthpurchaseid'+idx).value;
  cform.status.value = eval('obj.all.status'+idx).value;
}





//stock




//salesman
function popRep() {
	var regionid=cform.regionid.value;
	var proviceofficecode = document.cform.proviceofficelist.value;
	var businessareacode = document.cform.businessarealist.value;
	var status = "height=400, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
	var url = "<%=contextPath%>/tdr/dataverify/SalesPopWindow.jsp?<%= OvalTools.randomURL() %>&regionid="+regionid+"&proviceofficecode="+proviceofficecode+"&businessareacode="+businessareacode;
  
	popwindow = window.open(url, "newwindow", status);
  }

function SetSalesMan(id,code,name){
	cform.userids.value=id;
	cform.employeecode.value=code;
	cform.employeename.value=name;
}

//getsecond 
function page_getpriviceoffice(){
	var objdeptcode=eval("cform.regionid");
	if (objdeptcode==""){
	    return;
	}
	var  datahandler = new  DataHandler();
	datahandler.add_params("regionid" , objdeptcode.value , "Integer");
	datahandler.getResultFromVector("resultproviceoffice","proviceofficename","proviceofficecode","document.cform.proviceofficelist");
	datahandler.add_job("j_monthbuydatasummary");
	datahandler.runDataHandler();
  }



function page_getbusinessarea(){
	var objdeptcode=eval("cform.proviceofficelist");
	var regionid = document.cform.regionid.value;
	if (objdeptcode==""){
	    return;
	}
	var  datahandler = new  DataHandler();
	datahandler.add_params("regionid" , regionid , "Integer");
	datahandler.add_params("proviceofficelist" , objdeptcode.value , "String");
	datahandler.getResultFromVector("resultbusinessarea","businessareaname","businessareacode","document.cform.businessarealist");
	datahandler.add_job("j_monthbuydatasummary");
	datahandler.runDataHandler();
 }


function page_excel(){
	var id = document.cform.userid.value;	
	var partnerid =doument.cform.customerid.value;
	var orgid =document.cform.dealerid.value;
	<%if(!"Y".equals(issalesman)){%>
	var proviceofficecode = document.cform.proviceofficelist.value;
	var businessareacode = document.cform.businessarealist.value;
	var userids =document.cform.userids.value;
	var regionid= document.cform.regionid.value;
 	 window.location.href = "<%= reportURL %>/servlet/ExcecuteReport/MonthBuyData.sox?__folder=/ovalreport&rownum=2&employeeid="+ id+"&parentareaid="+regionid+"&areacode="+proviceofficecode+"&areacode1="+businessareacode+"&employeeids="+userids+"&partnerid="+customerid+"&orgid="+dealerid;	
	<% }else{  %>
	var salesman =document.cform.userid.value;
 		 window.location.href = "<%= reportURL %>/servlet/ExcecuteReport/MonthBuyData.sox?__folder=/ovalreport&rownum=2&employeeid="+ id+"&year="+year+"&month="+month+"&salesman="+salesman;	
 	<% }%>
 }

function popDealer() {
	  opt = "dealer";
	  var status = "height=450, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
			var url = "PathOrgSelect.jsp?o_thread=" + Math.random();
			url += "&globalpccode=112,113,114,117";
			if (typeof popwindow != 'undefined') popwindow.close();
			popwindow = window.open(url, "newwindow", status);
	}
	
	function popCustomer() {
	  opt = "customer";
	  var status = "height=450, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
			var url = "PathOrgSelect.jsp?o_thread=" + Math.random();
			url += "&globalpccode=99,112,117";
			
			if (typeof popwindow != 'undefined') popwindow.close();
			popwindow = window.open(url, "newwindow", status);
	}

	
   function page_setOrg(id, name, code) {
	  if(opt == "dealer"){
	  	document.cform.dealerid.value=id;
	  	document.cform.dealercode.value = code;
	  	document.cform.dealername.value = name;
	  }
	  if(opt == "customer"){
	  	document.cform.customerid.value=id;
	  	document.cform.customercode.value = code;
	  	document.cform.customername.value = name;
	  }	
	  opt = "";
	  if (popwindow != null)
	    popwindow.close();
	}

function page_checkpass(){
	if(checkBoxSeleceed()<1){
	     alert('<%=message.getMessageDesc("MUST_SELECT_ONE_RECORD")%>');
	     return ;
		}
	if(!confirm("<%=message.getMessageDesc("ZYL_TDR_YESPASS")%>"))
		return;
	    document.cform.target = "_self";
		document.cform.actionname.value="checkpass";
		isRunning = true;
		document.cform.submit();
	
}

function checkBoxSeleceed(){
	var obj=document.cform.historyofmonthpurchaseid;
	var j=0;
		for(var i=0;i<obj.length;i++)
		{
			if(obj[i].checked)
			{
					j++;
			}	
          }
        return j;
}

function page_allcheckselect(){
	var allcheck = cform.allcheck.checked;
	var alldatafile = document.getElementsByName('historyofmonthpurchaseid');
	var length = alldatafile.length;
	if(allcheck){
		for(var i = 0 ; i < length;i++){
			if(!alldatafile[i].disabled)
			alldatafile[i].checked = true;
		}
	}else{
		for(var i = 0 ; i < length;i++){
			alldatafile[i].checked = false;
		}	
	}
}
</script>
</head>

<body style="overflow: auto;">
  <iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_monthbuydatasummary">
    <input type="hidden" name="actionname">
<%--  page location   --%>
    <%@ include file="/inc/PageLocation.inc" %>
    <custom:hidden property="userid" name="userinfo" scope="session"></custom:hidden>
<custom:hidden property="globalpccode"></custom:hidden>

    <table width="100%" cellspacing="0" border="0" cellpadding="0">
      <tr>
<%--  search criteria  --%>
      </tr>
      <tr>
        <td>
          <table width="100%" border="0" cellspacing="0">
           <tr>
          <td class="summary_top" width="10%" colspan="3"></td>
          </tr>
           <%@ include file="/inc/SummarySearch.inc" %>
          </table>
        </td>
      </tr>
      
      	<tr>
        <td>
         <table width="770" border="0" cellspacing="0" >
   <tr>
    
     	<td><%= label.getLabelName("L_Partner") + label.getLabelName("L_Colon") %></td>
	          	<td>
	          		<custom:text property="customercode" size="10" readonly="true"/>
	            	<a onclick="javascript:popCustomer();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
	            	<custom:text property="customername" readonly="true" size="30"/>
	            	<custom:hidden property="customerid" />
	            </td>
	            <td >&nbsp;</td> <td > &nbsp;</td>
	          	<td><%= label.getLabelName("L_SellerOrg") + label.getLabelName("L_Colon") %></td>
	            <td>
	            	<custom:text property="dealercode" size="10" readonly="true"/>
	            	<a onclick="javascript:popDealer();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
	            	<custom:text property="dealername" readonly="true" size="30"/>
	            	<custom:hidden property="dealerid" />
	            </td>
     
     </tr>
  </table>
  <table width="100%" border="0" cellspacing="0" >
  <tr>
  
        	     <% 
	                if("Y".equals(issalesman)){
	             %> 
	                  <tr>
	                <td style="width:40px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               <td style="width:40px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               <td style="width:40px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               <td style="width:60px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               <td style="width:60px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               </tr>
	                <%}else{ %>
        	    <tr>
        	    <td style="width:40px;" class="td_right"><%=label.getLabelName("L_Businessarea") +  label.getLabelName("L_Colon") %></td>
        	  	<td style="width:160px;" class="td_left"><custom:select property="regionid" optionInnerTextKey="regionname" style="width:160px" optionsName="resultregion" optionValueKey="regionid" onchange="page_getpriviceoffice()" defaultValue="ALL" defaultValueCost=""/></td>
        	    <td style="width:40px;" class="td_right"><%=label.getLabelName("L_ProvinceOffice") +  label.getLabelName("L_Colon") %></td>
				<td style="width:150px;" class="td_left">
					<custom:select property="proviceofficelist" optionInnerTextKey="proviceofficename" optionsName="resultproviceoffice" optionValueKey="proviceofficecode" defaultValue="----------" style="width:150px" defaultValueCost="" onchange="page_getbusinessarea();"/>
		        </td>
			    <td style="width:60px;" class="td_right"><%=label.getLabelName("L_BusinessAreaName") +  label.getLabelName("L_Colon") %></td>
				<td style="width:180px;" class="td_left">
				<custom:select property="businessarealist" optionInnerTextKey="businessareaname" optionsName="resultbusinessarea" optionValueKey="businessareacode" defaultValue="----------" style="width:180px" defaultValueCost=""/> </td>
        	     <td style="width:60px;" class="td_right"><%=label.getLabelName("L_BusinessContact") +  label.getLabelName("L_Colon") %></td>
				<td style="width:150px;">
			<custom:text property="employeename" size="20" readonly="true" style="border:1px #7F9DB9 solid;"/>
			<a onClick="javascript:popRep();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a> 
			<custom:hidden property="userids"/>
			<custom:hidden property="employeecode"/>
		   </td>
				<td style="20px;"><button type="reset" class="button1" name="re" value="clear"  style="width:60"><%=label.getLabelName("L_Clear") %></button></td>
			<%} %>
        	</tr>
          </table>
        </td>
      </tr>
      <tr>
        <td>
          <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">

<%
    ArrayList titleTdArray = new ArrayList();
   // titleTdArray.add(new TD("22","&nbsp;"));
   titleTdArray.add(new TD("22","<input type='checkbox' name='allcheck' style='border:0;' onclick='page_allcheckselect()'"));
    titleTdArray.add(new TitleTD("70","L_Date","startdate") );
    titleTdArray.add(new TitleTD("80","L_PartCodeC","orgcode"));
    titleTdArray.add(new TitleTD("200","L_PartNameN","orgname"));
    titleTdArray.add(new TitleTD("200","L_CustomerBeforeName","vendororiginame"));
    titleTdArray.add(new TitleTD("50","L_TerminalCode","partnercode"));
    titleTdArray.add(new TitleTD("200","L_TerminalName","partnername"));
    titleTdArray.add(new TitleTD("50","L_ProdCode","itemcode"));
    titleTdArray.add(new TitleTD("120","L_ProdName","itemnamecn"));
    titleTdArray.add(new TitleTD("70","L_Quantity","qty"));
    titleTdArray.add(new TitleTD("50","L_Status","statusname"));
 %>
    <custom:titletr styleClass="deepblue-left" tdArray="<%=titleTdArray%>" />

 <%
     ArrayList detailTdArray = new ArrayList();
     //detailTdArray.add(new RadioTD());
     //titleTdArray.add(new TD("22","<input type=\"checkbox\" onclick=''"));
     detailTdArray.add(new CheckBoxTD("historyofmonthpurchaseid"));
     detailTdArray.add(new WriteTD("startdate"));
     detailTdArray.add(new WriteTD("orgcode"));
     detailTdArray.add(new WriteTD("orgname"));
     detailTdArray.add(new WriteTD("vendororiginame"));
     detailTdArray.add(new WriteTD("partnercode"));
     detailTdArray.add(new WriteTD("partnername"));
     detailTdArray.add(new WriteTD("itemcode"));
     detailTdArray.add(new WriteTD("itemnamecn"));
     detailTdArray.add(new WriteTD("qty"));
     detailTdArray.add(new WriteTD("statusname"));
     

     
     
     ArrayList hiddenArray = new ArrayList();
     //hiddenArray.add(new HiddenInput("historyofmonthpurchaseid",true));
     hiddenArray.add(new HiddenInput("status",true));
 %>
    <custom:iteratetr tdArray="<%=detailTdArray%>" hiddenArray="<%=hiddenArray%>"  dataSource="totalsummary"/>
            <tr> 
	          <td colspan="9" style="text-align:right"><%=label.getLabelName("L_PageSum") +  label.getLabelName("L_Colon")%></td>
				<td class="red"><b><custom:write name="sumhash" property="sumqty" nbsp="true"/></b></td>
				<td>&nbsp;</td>
	        </tr>
	        <tr> 
	          <td colspan="9" style="text-align:right"><%=label.getLabelName("L_TotalSum") +  label.getLabelName("L_Colon")%></td>
				<td class="red"><b><custom:write name="sumhash" property="summonthqty" nbsp="true" dataType="number" dataFormatName="qtyviewformat" /></b></td>
	        <td>&nbsp;</td>
	         <%@ include file="/inc/SummaryAction.inc" %>
	        </tr>

          </table>
          <table width="100%" cellspacing="0" cellpadding="0">
            <tr><td class="summary_top"></td></tr>
            <tr>
              <td class="td_center">
                   <td class="td_center">
              	<%if(pageContext.getAttribute("totalsummary")!=null){%>
              	<a onclick="page_excel();"><custom:button type="1" label="L_ExcelE" imgsrc="Modify.gif" border="0" style="width:100"/></a>&nbsp;&nbsp;
                <a onclick="page_checkpass();"><custom:button type="1" label="L_CheckPass" imgsrc="Modify.gif" border="0" style="width:100"/></a>&nbsp;&nbsp;
                <% } %>
           
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
</form>
</body>
<script type="text/javascript">
for (var i=0;i<cform.historyofmonthpurchaseid.length;i++){
	if(eval('cform.status'+i).value == "41"){
     cform.historyofmonthpurchaseid[i].disabled =true ;
	}
}

</script>
</html>

